package com.app.util.db;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.Properties;

public class ConnectionCreater {

	private String url;
	private String user;
	private String password;
	private Driver driver;

	public ConnectionCreater(String clazz, String url, String user, String password) throws SQLException {
		try {
			driver = (Driver) Class.forName(clazz).newInstance();
		} catch (Exception e) {
			throw new SQLException(e);
		}
		this.url = url;
		this.user = user;
		this.password = password; 
	}

	public Connection newConnection() throws SQLException {
		Properties info = new Properties();
		if (user != null) {
			info.put("user", user);
		}
		if (password != null) {
			info.put("password", password);
		}
		Connection con = driver.connect(url, info);
		return con;
	}

}
